<template>
	<view class="pb-safe-area">
		<view class="p-4 flex flex-column grid-gap-4">
			<view class="flex bg-white rounded-4 p-4 flex-center grid-gap-2" @tap="$page.open('/pages/user/account/mobile')">
				<text class="flex-1 h9 text-grey">绑定手机</text>
				<text class="h9 font-weight-600">{{ USERINFO.mobile }}</text>
				<uni-icons type="right" color="var(--xl-placeholder)"></uni-icons>
			</view>
			<view class="flex bg-white rounded-4 p-4 flex-center grid-gap-2"
				@tap="$page.open('/pages/user/account/password')">
				<text class="flex-1 h9 text-grey">修改密码</text>
				<uni-icons type="right" color="var(--xl-placeholder)"></uni-icons>
			</view>
			<view class="flex bg-white rounded-4 p-4 flex-center grid-gap-2" v-if="WEBCONFIG?.wx_state"
				@tap="bindWechat">
				<text class="flex-1 h9 text-grey">绑定微信</text>
				<!-- #ifdef H5 -->
				<text class="h9 font-weight-600" v-if="USERINFO?.openid">{{ USERINFO.wechat_nickname }}</text>
				<!-- #endif -->
				<!-- #ifdef MP-WEIXIN -->
				<text class="h9 font-weight-600" v-if="USERINFO?.mp_openid">{{ USERINFO.wechat_nickname }}</text>
				<!-- #endif -->
				<!-- #ifdef APP -->
				<text class="h9 font-weight-600" v-if="USERINFO?.app_openid">{{ USERINFO.wechat_nickname }}</text>
				<!-- #endif -->
				<text class="h9 font-weight-600" v-else>未绑定</text>
				<uni-icons type="right" color="var(--xl-placeholder)"></uni-icons>
			</view>
			<view class="flex bg-white rounded-4 p-4 flex-center grid-gap-2"
				@tap="$page.open('/pages/user/finance/index')">
				<text class="flex-1 h9 text-grey">收款账户</text>
				<uni-icons type="right" color="var(--xl-placeholder)"></uni-icons>
			</view>
		</view>
	</view>
</template>

<script setup lang="ts">
import { ref } from 'vue';
import { useWebConfigStore, useUserStore, useRefs } from "@/stores";
import { $page, $api, $message } from "@/utils";
const WebConfigStore = useWebConfigStore();
const { WEBCONFIG } = useRefs(WebConfigStore);
const UserStore = useUserStore();
const { USERINFO } = useRefs(UserStore);

const bindWechat = () => {
	// #ifdef H5
	if (!USERINFO.value.openid) {
		$api.User.bindWechat({
			redirect: 'bind'
		})
			.then((res: any) => {
				globalThis.location.href = res.data;
			}).catch((err: any) => {
				$message.error(err.msg);
			});
	} else {
		uni.showModal({
			title: '提示',
			content: '是否解除绑定',
			success: (res: any) => {
				if (res.confirm) {
					$api.User.unBindWechat().then(() => {
						$api.User.userinfo(true);
						$message.success('解绑成功');
					}).catch((err: any) => {
						$message.error(err.msg);
					})
				}
			}
		})
	}
	// #endif
}
</script>

<style lang="scss" scoped></style>
